﻿CREATE TABLE [CO].[LedgerTransTypes] (
    [Id]                    INT           NOT NULL,
    [Name]                  VARCHAR (100) NOT NULL,
    [DebitLedgerAccountId]  INT           NOT NULL,
    [DebitSubcontoTypeId1]  INT           CONSTRAINT [DF_LedgerTransTypes_DebitSubcontoTypeId1] DEFAULT ((1)) NOT NULL,
    [DebitSubcontoTypeId2]  INT           CONSTRAINT [DF_LedgerTransTypes_DebitSubcontoTypeId2] DEFAULT ((1)) NOT NULL,
    [DebitSubcontoTypeId3]  INT           CONSTRAINT [DF_LedgerTransTypes_DebitSubcontoTypeId3] DEFAULT ((1)) NOT NULL,
    [DebitSubcontoTypeId4]  INT           CONSTRAINT [DF_LedgerTransTypes_DebitSubcontoTypeId4] DEFAULT ((1)) NOT NULL,
    [DebitSubcontoTypeId5]  INT           CONSTRAINT [DF_LedgerTransTypes_DebitSubcontoTypeId5] DEFAULT ((1)) NOT NULL,
    [CreditLedgerAccountId] INT           NOT NULL,
    [CreditSubcontoTypeId1] INT           CONSTRAINT [DF_LedgerTransTypes_CreditSubcontoTypeId1] DEFAULT ((1)) NOT NULL,
    [CreditSubcontoTypeId2] INT           CONSTRAINT [DF_LedgerTransTypes_CreditSubcontoTypeId2] DEFAULT ((1)) NOT NULL,
    [CreditSubcontoTypeId3] INT           CONSTRAINT [DF_LedgerTransTypes_CreditSubcontoTypeId3] DEFAULT ((1)) NOT NULL,
    [CreditSubcontoTypeId4] INT           CONSTRAINT [DF_LedgerTransTypes_CreditSubcontoTypeId4] DEFAULT ((1)) NOT NULL,
    [CreditSubcontoTypeId5] INT           CONSTRAINT [DF_LedgerTransTypes_CreditSubcontoTypeId5] DEFAULT ((1)) NOT NULL,
    [Note]                  VARCHAR (250) NULL,
    [MD]                    DATETIME      CONSTRAINT [DF__LedgerTransT__MD__7FC0E00C] DEFAULT (getdate()) NOT NULL,
    [MW]                    VARCHAR (50)  CONSTRAINT [DF__LedgerTransT__MW__00B50445] DEFAULT (suser_sname()) NOT NULL,
    [ToDelete]              BIT           DEFAULT ((0)) NOT NULL,
    CONSTRAINT [PK_LedgerTransTypes] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_LedgerTransType_CreditSubcontoType1] FOREIGN KEY ([CreditSubcontoTypeId1]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_CreditSubcontoType2] FOREIGN KEY ([CreditSubcontoTypeId2]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_CreditSubcontoType3] FOREIGN KEY ([CreditSubcontoTypeId3]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_CreditSubcontoType4] FOREIGN KEY ([CreditSubcontoTypeId4]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_CreditSubcontoType5] FOREIGN KEY ([CreditSubcontoTypeId5]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_DebitLedgerAccount] FOREIGN KEY ([DebitLedgerAccountId]) REFERENCES [CO].[LedgerAccounts] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_DebitSubcontoType1] FOREIGN KEY ([DebitSubcontoTypeId1]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_DebitSubcontoType2] FOREIGN KEY ([DebitSubcontoTypeId2]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_DebitSubcontoType3] FOREIGN KEY ([DebitSubcontoTypeId3]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_DebitSubcontoType4] FOREIGN KEY ([DebitSubcontoTypeId4]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransType_DebitSubcontoType5] FOREIGN KEY ([DebitSubcontoTypeId5]) REFERENCES [CO].[LedgerSubcontoTypes] ([Id]) NOT FOR REPLICATION,
    CONSTRAINT [FK_LedgerTransTypes_CreditLedgerAccounts] FOREIGN KEY ([CreditLedgerAccountId]) REFERENCES [CO].[LedgerAccounts] ([Id]) NOT FOR REPLICATION
);


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Признак того, что запись нужно удалить из БД всех подразделений', @level0type = N'SCHEMA', @level0name = N'CO', @level1type = N'TABLE', @level1name = N'LedgerTransTypes', @level2type = N'COLUMN', @level2name = N'ToDelete';

